<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="z" uri="zz"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<%@include file="/views/common/common.jsp"%>
	<script type="text/javascript">

		//验证客户新主号是否有效
		function vNewCustomID(){
			var new_customid = $("#new_customid_id").val();
			if(isNotNull(new_customid)){
				$.ajax({
					type : "get",
					url : "http://pdh.grxx.cc/api/getCustomer",
					data:{_sign:'1111111',zid:new_customid},
					success : function(data) {

						if(data.code=='SUCCESS'){
							$("#isok").text('有效');
							var returninfo = decodeURIComponent(data.data);
							$("#info_id").val(returninfo);
							var json = JSON.parse(returninfo);
						}else{
							$("#isok").text('无效');
							var returninfo = decodeURIComponent(data.msg);
							$("#info_id").val(returninfo);
						}
					},
					error: function (data) {
						$("#info_id").val('ajax错误：'+JSON.stringify(data));
					}
				});
			}else{
				parent.alertErrorMessager('客户新主号不能为空');
			}
		}


		//执行更换主号
		function RunRecharge(){
			var isok = $("#isok").text();
			var customid = $("#userid_id").val();
			var new_customid = $("#new_customid_id").val();

			if(isok=='有效'){
				if(isNotNull(customid)){
					if(isNotNull(new_customid)){
						$.messager.confirm('信息提示','您确定要执行吗？',function(r){
							if (r){
								$.ajax({
									type : "get",
									url : "zs",
									data:{serviceid:'ReplaceCustomerMainNumber',customid:customid,new_customid:new_customid},
									success : function(data) {
										if(data.code=='SUCCESS'){
											parent.alertMessager('更换成功');
											location.reload();
										}else{
											parent.alertErrorMessager(data.msg);
										}
									},
									error: function (data) {
										parent.alertErrorMessager('ajax错误：'+JSON.stringify(data));
									}
								});
							}
						});
					}else{
						parent.alertErrorMessager('新客户账号不能为空');
					}
				}else{
					parent.alertErrorMessager('原客户账号不能为空');
				}
			}else{
				parent.alertErrorMessager('客户新主号未通过验证');
			}


		}

	</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" class="border-top-0 border-right-0 border-left-0" style="height:38px;overflow:hidden">
	<div id="ButtonHR" class="btn-group" role="group">
		<c:if test="${is_mobile=='1'}" >
			<button id="return_button" type="button" class="btn btn-light" onclick="window.location.href='user_center_mobile';"><i class="fa fa-hand-o-left"></i> 返回</button>
		</c:if>
		<button id="RunRechargeButton" type="button" class="btn btn-light" onclick="RunRecharge();"><i class="fa fa-floppy-o"></i> 执行更换主号</button>
		<button id="vNewCustomIDButton" type="button" class="btn btn-light" onclick="vNewCustomID()"><i class="fa fa-floppy-o"></i> 验证客户新主号是否有效</button>
	</div>
</div>
<div data-options="region:'center',border:false">
	<z:column column_size="4" column_type="8" column_id="userid" column_name="原客户账号" column_help="原客户账号" tableId="erp_account" z5_table="crm_customer" z5_key="zid" z5_value="name"  />
	<z:column column_size="4" column_type="0" column_id="new_customid" column_name="客户新主号" is_readonly="true" column_help="客户新主号" />
	<span style="padding-left: 30px;">是否有效：<span id="isok">未验证</span></span>
	<z:column column_size="4" column_type="1" column_id="info" column_name="直销接口返回信息" column_help="直销接口返回信息" />
</div>

<%@include file="/views/common/body.jsp"%>
</body>
</html>